package com.tg.demo.sentinel.controller;

import cn.hutool.core.date.DateUtil;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author Rubble
 * Created on 2020/5/21
 */
@Slf4j
@RestController
public class HelloSentinelController {

    @GetMapping(value = "/hello")
    @SentinelResource(value = "hello",blockHandler = "helloHandler",fallback = "fallback")
    public String hello() {
        return "Hello Sentinel";
    }

    public String helloHandler(BlockException ex){
        return "block limit helloHandler  "+ DateUtil.formatDateTime(new Date());
    }

    public String fallback(){
        return "Hello Sentinel fallback";
    }
}
